/**
 * 基于时间生成的随机订单号，具有唯一性
 *
 * @returns 随机订单号
 */
const randomList = (): string => {
  function setTimeDateFmt(s: number): string {
    // 个位数补齐十位数
    return s < 10 ? "0" + s : s + "";
  }
  function createordernum() {
    const now = new Date();
    let month: string | number = now.getMonth() + 1;
    let day: string | number = now.getDate();
    let hour: string | number = now.getHours();
    let minutes: string | number = now.getMinutes();
    let seconds: string | number = now.getSeconds();
    month = setTimeDateFmt(month);
    day = setTimeDateFmt(day);
    hour = setTimeDateFmt(hour);
    minutes = setTimeDateFmt(minutes);
    seconds = setTimeDateFmt(seconds);
    let orderCode =
      now.getFullYear().toString() +
      month.toString() +
      day +
      hour +
      minutes +
      seconds +
      Math.round(Math.random() * 1000000).toString();
    return orderCode;
    //基于年月日时分秒+随机数生成订单编号
  }
  return createordernum();
};

export { randomList };
